package org.jetlinks.community.mstn.entity.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hswebframework.ezorm.core.utils.StringUtils;
import org.jetlinks.community.auth.entity.OrganizationEntity;
import org.jetlinks.community.auth.entity.RoleEntity;
import org.jetlinks.community.auth.enums.OrgType;
import org.jetlinks.community.auth.enums.RoleType;
import org.jetlinks.community.mstn.enums.ProjectType;

import java.util.Map;

@Data
public class ProjectCreateReqVO {

    @Schema(description = "用户ID")
    private String userId;

    @Schema(description = "租户ID")
    private String orgId;

    @Schema(description = "租户套餐ID")
    private String roleId;

    @Schema(description = "项目名称")
    private String name;

    @Schema(description = "说明")
    private String describe;

    @Schema(description = "其他配置")
    private Map<String, Object> properties;

    @Schema(description = "过期时间")
    private Long expireTime;

    private RoleEntity roleInfo;

    public OrganizationEntity getMultiOrganization(){
        OrganizationEntity organization = new OrganizationEntity();
        if (!StringUtils.isNullOrEmpty(getOrgId())) {
            organization.setId(getOrgId());
            organization.setExpireTime(getExpireTime());
        }else {
            if (getExpireTime() == null) {
                organization.setExpireTime(0L);
            } else {
                organization.setExpireTime(getExpireTime());
            }
        }
        organization.setContactUserId(getUserId());
        organization.setOrgType(OrgType.project);
        organization.setName(getName());
        organization.setDescribe(getDescribe());
        organization.setProjectType(ProjectType.collect.getValue());
        organization.setProperties(getProperties());
        organization.setPackageId(getRoleId());
        return organization;
    }

}
